<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/1
 * Time: 12:30
 */

namespace Api\Controller;
class AlipayPayController extends CommonController {
    public function AjaxQueryOrderStatus($order_number){
        if(!empty($order_number)){
            $orderstatus = M("Transaction")->field('pay_status,callback_url')->where(array('systrade_no' => $order_number , 'pay_type' => 'alipay_pay'))->find();
            if($orderstatus['pay_status'] == "1") {
                $this->ajaxReturn(array('status' => 1, 'return_url' => $orderstatus['callback_url']));
            }else{
                $this->ajaxReturn(array('status' => 0 , 'return_url' => ''));
            }
        }
    }

    private static function qrcode($url){
        Vendor('phpqrcode.phpqrcode');
        $level = 'L';
        $size = 6;
        $file_Imgname = "./Public/WeixinCode/" . randNumber('WeixinCode') . '.png';
        \QRcode::png($url, $file_Imgname, $level, $size);
        return S_URL . ltrim($file_Imgname , '.');
    }

    // 不需要登录，玩家可以使用其他浏览器打开此页面进行调起支付宝
    public function ocdiaoqizhifuSM(){
        $sign = I('get.Sign');
        $pay_url = base64_decode(I('get.payurl'));
        $order_number = base64_decode(I('get.order'));
        $MySign = strtoupper(md5($pay_url  . $order_number. C("SignKey")));
        if($sign != $MySign) exit('sign error');
        if($this->isWx() || $_GET['is_alipay'] != "true") {
            $this->assign('order_number' , $order_number);
            $this->assign('img' , AlipayPayController::qrcode($pay_url));
            if($_GET['is_alipay'] == "true") {
                // $this->display('CreatePay:alipay_sm');
                $this->display('CreatePay:alipay'); // 引导用户使用微信外部浏览器打开
            }else{
                $this->display('CreatePay:wx_sm');
            }
        }else{
            header("Location:" . $pay_url);
        }
    }



//﻿    // 不需要登录，玩家可以使用其他浏览器打开此页面进行调起支付宝
//    public function ocdiaoqizhifuSM(){
//        $sign = I('get.Sign');
//        $pay_url = base64_decode(I('get.payurl'));
//        $order_number = base64_decode(I('get.order'));
//        $MySign = strtoupper(md5($pay_url  . $order_number. C("SignKey")));
//        if($MySign != $sign) exit('sign error');
//        if($this->isWx()) {
//            $this->assign('order_number' , $order_number);
//            $this->display('CreatePay:alipay');
//        }else{
//            header("Location:" . $pay_url);
//        }
//    }


}